package com.example.task01_servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ForwardServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("接收到了浏览器的请求!");
        //向request对象中设置属性信息
        request.setAttribute("key1","value1");
        //转发 也就是让web组件将任务转交给另外一个web组件
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/target");
        requestDispatcher.forward(request,response);
    }
}
